﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Bean;
using System.Collections;
using Shpm.System.Db;


namespace Shpm.App.Input.Dao
{
    public class EmployeeDinnerDao : ShpmBaseDao
    {
        public EmployeeDinnerDao()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        //职员订餐LIST
        public const string LIST_EMPLOYEE_DINNER = "EmployeeDinner.ListEmployeeDinners";
        //读取菜单信息
        public const string GET_EMPLOYEE_DINNER = "EmployeeDinner.GetEmployeeDinner";
        //读取菜单
        public const string LIST_EMPLOYEE_DINNER_DETAILS = "EmployeeDinner.ListEmployeeDinnerDetails";
        //
        public const string GET_EMPLOYEE_DINNER_DETAIL = "EmployeeDinner.LoadEmployeeDinnerDetail";
        //
        public const string INS_EMPLOYEE_DINNER = "EmployeeDinner.InsEmployeeDinner";
        //
        public const string INS_EMPLOYEE_DINNER_DETAIL = "EmployeeDinner.InsEmployeeDinnerDetail";
        //
        public const string UPD_EMPLOYEE_DINNER = "EmployeeDinner.UpdEmployeeDinner";
        //
        public const string DEL_EMPLOYEE_DINNER_DETAIL = "EmployeeDinner.DelEmployeeDinnerDetail";

        /*
         *名称： ListEmployeeDinners
         *功能： 读取对象。
         *参数： paramBean 
         *返回： IList
         *说明： 
        */
        public IList ListEmployeeDinners(EmployeeDinnerBean  paramBean)
        {
            return base.QueryForList(LIST_EMPLOYEE_DINNER, paramBean);
        }

        /*
         *名称： GetEmployeeDinner
         *功能： 读取对象。
         *参数： paramBean 
         *返回： 读取的对象
         *说明： 
        */
        public EmployeeDinnerBean GetEmployeeDinner(EmployeeDinnerBean paramBean)
        {
            return (EmployeeDinnerBean)base.QueryForObject(GET_EMPLOYEE_DINNER, paramBean);
        }

        /*
         *名称： ListEmployeeDinnerDetails
         *功能： 读取对象。
         *参数： paramBean 
         *返回： IList
         *说明： 
        */
        public IList ListEmployeeDinnerDetails(EmployeeDinnerDetailBean paramBean)
        {
            return base.QueryForList(LIST_EMPLOYEE_DINNER_DETAILS, paramBean);
        }

        public EmployeeDinnerDetailBean GetEmployeeDinnerDetail(EmployeeDinnerDetailBean paramBean)
        {
            return (EmployeeDinnerDetailBean)base.QueryForObject(GET_EMPLOYEE_DINNER_DETAIL, paramBean);
        }

        public object InsEmployeeDinner(EmployeeDinnerBean paramBean)
        {
            return base.Insert(INS_EMPLOYEE_DINNER, paramBean);
        }
        public object InsEmployeeDinnerDetail(EmployeeDinnerDetailBean paramBean)
        {
            return base.Insert(INS_EMPLOYEE_DINNER_DETAIL, paramBean);
        }
        public int UpdEmployeeDinner(EmployeeDinnerBean paramBean)
        {
            return base.Update(UPD_EMPLOYEE_DINNER, paramBean);
        }
        public int DelEmployeeDinnerDetail(EmployeeDinnerDetailBean paramBean)
        {
            return base.Delete(DEL_EMPLOYEE_DINNER_DETAIL, paramBean);
        }


        public int Insert(IList list, EmployeeDinnerBean dataBean)
        {
            try
            {
                base.BeginTransaction();
                //会员订餐信息
                int dinnerId = (int)InsEmployeeDinner(dataBean);

                //会员订餐信息_详细
                EmployeeDinnerDetailBean bean = new EmployeeDinnerDetailBean();
                for (int i = 0; i < list.Count; i++)
                {
                    bean = (EmployeeDinnerDetailBean)list[i];
                    bean.DinnerId = dinnerId;
                    //bean.DishId = paramBean.DishId;
                    //bean.DishPrice = paramBean.DishPrice;
                    //bean.DishQuantity = paramBean.DishQuantity;
                    bean.UserId = dataBean.UserId;
                    InsEmployeeDinnerDetail(bean);
                }
                base.CommitTransaction();
                return dinnerId;
            }
            catch (Exception e)
            {
                //log.Fatal(e);
                base.RollBackTransaction();
                throw new DataAccessException(e);
            }
        }

        public void Upd(IList list, EmployeeDinnerBean paramBean)
        {
            try
            {
                base.BeginTransaction();
                UpdEmployeeDinner(paramBean);
                EmployeeDinnerDetailBean bean = new EmployeeDinnerDetailBean();
                bean.DinnerId = paramBean.DinnerId;
                DelEmployeeDinnerDetail(bean);

                for (int i = 0; i < list.Count; i++)
                {
                    bean = (EmployeeDinnerDetailBean)list[i];
                    bean.DinnerId = paramBean.DinnerId;
                    bean.UserId = paramBean.UserId;
                    InsEmployeeDinnerDetail(bean);
                }

                base.CommitTransaction();
            }
            catch (Exception e)
            {
                //log.Fatal(e);
                base.RollBackTransaction();
                throw new DataAccessException(e);
            }
        }
    }
}